﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CreateBullet : MonoBehaviour
{
    public GameObject bullet;
    public Transform spawnPosition;
    public float speed = 10;
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            RaycastHit hit;
            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100f))
            {
                GameObject projectile = Instantiate(bullet, spawnPosition.position, Quaternion.identity) as GameObject;
                projectile.transform.LookAt(hit.point);
                projectile.GetComponent<Rigidbody>().AddForce(projectile.transform.forward * speed);
                projectile.GetComponent<ProjectileScript>().impactNormal = hit.normal;
            }

        }
    }
}
